<!DOCTYPE html>



  


<html class="theme-next gemini use-motion" lang="zh-CN">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<meta name="theme-color" content="#222">






  
  
    
    
  <script src="/lib/pace/pace.min.js?v=1.0.2"></script>
  <link href="/lib/pace/pace-theme-minimal.min.css?v=1.0.2" rel="stylesheet">







<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />







<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=6.0.4" rel="stylesheet" type="text/css" />


  <link rel="apple-touch-icon" sizes="180x180" href="/img/apple-touch-icon.jpg?v=6.0.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/img/favicon-32x32.jpg?v=6.0.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/img/favicon-16x16.jpg?v=6.0.4">


  <link rel="mask-icon" href="/img/logo.svg?v=6.0.4" color="#222">









<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Gemini',
    version: '6.0.4',
    sidebar: {"position":"right","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    fastclick: false,
    lazyload: false,
    tabs: true,
    motion: {"enable":true,"async":true,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>


  




  
  <meta name="keywords" content="hexo,Hexo博客搭建,Hexo Github Coding" />


<meta name="description" content="这是一篇使用Hexo和GitHubPages 和CodingPages搭建免费独立博客的总结。 GitHub Pages 和 Coding Pages本用于托管在 GitHub 顿号 Coding项目的介绍，可以存放静态页,所以也可以用来搭建博客。 Hexo是一个基于Node.js的静态博客程序，可以方便的生成静态网页托管在github和Coding上。">
<meta name="keywords" content="hexo,Hexo博客搭建,Hexo Github Coding">
<meta property="og:type" content="article">
<meta property="og:title" content="Hexo搭建Github+Coding双线博客">
<meta property="og:url" content="http://yimao.info/2018/02/19/hexo-to-github-and-coding/index.html">
<meta property="og:site_name" content="Yimao&#39;s Blog">
<meta property="og:description" content="这是一篇使用Hexo和GitHubPages 和CodingPages搭建免费独立博客的总结。 GitHub Pages 和 Coding Pages本用于托管在 GitHub 顿号 Coding项目的介绍，可以存放静态页,所以也可以用来搭建博客。 Hexo是一个基于Node.js的静态博客程序，可以方便的生成静态网页托管在github和Coding上。">
<meta property="og:locale" content="zh-CN">
<meta property="og:image" content="https://wx4.sinaimg.cn/large/006e1QBjly1folevzdp97j30w40e9tdu.jpg">
<meta property="og:image" content="https://wx1.sinaimg.cn/large/006e1QBjly1folga6pgr0j30xz0kz75q.jpg">
<meta property="og:image" content="https://wx2.sinaimg.cn/large/006e1QBjly1folgn0lguuj30y20biq43.jpg">
<meta property="og:image" content="https://wx1.sinaimg.cn/large/006e1QBjly1folgxyd03ej30rb0ksq46.jpg">
<meta property="og:image" content="https://wx1.sinaimg.cn/large/006e1QBjly1foli9t79o3j30yg0fht9p.jpg">
<meta property="og:image" content="https://wx1.sinaimg.cn/large/006e1QBjly1folicfapwgj30zb0i5wfw.jpg">
<meta property="og:image" content="https://wx1.sinaimg.cn/large/006e1QBjly1folhyrdyk8j30z20ebdh7.jpg">
<meta property="og:image" content="https://wx1.sinaimg.cn/large/006e1QBjly1folityz3u7j30rs0o6q4j.jpg">
<meta property="og:image" content="https://wx1.sinaimg.cn/large/006e1QBjly1foljbgzsjhj312o0dlwf9.jpg">
<meta property="og:image" content="https://wx1.sinaimg.cn/large/006e1QBjly1folj4v4p00j311a0nd75o.jpg">
<meta property="og:image" content="https://wx1.sinaimg.cn/large/006e1QBjly1foljvjtxinj30yx0f4my6.jpg">
<meta property="og:image" content="https://wx1.sinaimg.cn/large/006e1QBjly1folk0lttpcj30zb0i5wfw.jpg">
<meta property="og:image" content="https://wx1.sinaimg.cn/large/006e1QBjly1folm3vebdfj31fq0qgqjg.jpg">
<meta property="og:updated_time" content="2018-02-19T04:03:42.000Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Hexo搭建Github+Coding双线博客">
<meta name="twitter:description" content="这是一篇使用Hexo和GitHubPages 和CodingPages搭建免费独立博客的总结。 GitHub Pages 和 Coding Pages本用于托管在 GitHub 顿号 Coding项目的介绍，可以存放静态页,所以也可以用来搭建博客。 Hexo是一个基于Node.js的静态博客程序，可以方便的生成静态网页托管在github和Coding上。">
<meta name="twitter:image" content="https://wx4.sinaimg.cn/large/006e1QBjly1folevzdp97j30w40e9tdu.jpg">






  <link rel="canonical" href="http://yimao.info/2018/02/19/hexo-to-github-and-coding/"/>



<script type="text/javascript" id="page.configurations">
  CONFIG.page = {
    sidebar: "",
  };
</script>
  <title>Hexo搭建Github+Coding双线博客 | Yimao's Blog</title>
  






  <script type="text/javascript">
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "https://hm.baidu.com/hm.js?755ebcd50db7676f6a985c847ea3071a";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>




  <noscript>
  <style type="text/css">
    .use-motion .motion-element,
    .use-motion .brand,
    .use-motion .menu-item,
    .sidebar-inner,
    .use-motion .post-block,
    .use-motion .pagination,
    .use-motion .comments,
    .use-motion .post-header,
    .use-motion .post-body,
    .use-motion .collection-title { opacity: initial; }

    .use-motion .logo,
    .use-motion .site-title,
    .use-motion .site-subtitle {
      opacity: initial;
      top: initial;
    }

    .use-motion {
      .logo-line-before i { left: initial; }
      .logo-line-after i { right: initial; }
    }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-CN">

  
  
    
  

  <div class="container sidebar-position-right page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"> <div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">Yimao's Blog</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle">不积跬步,无以至千里。</p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            <i class="menu-item-icon fa fa-fw fa-home"></i> <br />首页</a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags/" rel="section">
            <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />标签</a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories/" rel="section">
            <i class="menu-item-icon fa fa-fw fa-th"></i> <br />分类</a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives/" rel="section">
            <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />归档</a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/about/" rel="section">
            <i class="menu-item-icon fa fa-fw fa-user"></i> <br />关于</a>
        </li>
      

      
    </ul>
  

  
</nav>


  



 </div>
    </header>
    
   

   
    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://yimao.info/2018/02/19/hexo-to-github-and-coding/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="一毛">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/img/avatar.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Yimao's Blog">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">Hexo搭建Github+Coding双线博客</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2018-02-19T12:03:42+08:00">2018-02-19</time>
            

            
            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing"><a href="/categories/Blog/" itemprop="url" rel="index"><span itemprop="name">Blog</span></a></span>

                
                
              
            </span>
          

          
            
          

          
          
             <span id="/2018/02/19/hexo-to-github-and-coding/" class="leancloud_visitors" data-flag-title="Hexo搭建Github+Coding双线博客">
               <span class="post-meta-divider">|</span>
               <span class="post-meta-item-icon">
                 <i class="fa fa-eye"></i>
               </span>
               
                 <span class="post-meta-item-text">热度&#58;</span>
               
                 <span class="leancloud-visitors-count"></span>
                 <span>℃</span>
             </span>
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <p><strong>这是一篇使用<code>Hexo</code>和<code>GitHubPages</code> 和<code>CodingPages</code>搭建免费独立博客的总结。</strong></p>
<p>GitHub Pages 和 Coding Pages本用于托管在 GitHub 顿号 Coding项目的介绍，可以存放静态页,所以也可以用来搭建博客。</p>
<p>Hexo是一个基于Node.js的静态博客程序，可以方便的生成静态网页托管在github和Coding上。<br><a id="more"></a><br>以下提到的<strong>站点配置文件</strong>指的是博客文件根目录下的 <code>_config.yml</code>，<strong>主题配置文件</strong>是主题文件夹下的 <code>_config.yml</code>，童鞋们不要混淆了</p>
<h2 id="1-环境"><a href="#1-环境" class="headerlink" title="1.环境"></a>1.环境</h2><blockquote>
<ul>
<li>Windows</li>
<li><a href="http://www.yimao.info/tags/#Hexo" target="_blank" rel="noopener">Hexo</a> </li>
<li><a href="http://www.yimao.info/tags/#git" target="_blank" rel="noopener">Git</a></li>
<li><a href="http://www.yimao.info/tags/#node.js" target="_blank" rel="noopener">Node.js</a></li>
<li><a href="http://www.yimao.info/tags/#github" target="_blank" rel="noopener">Github</a></li>
<li><a href="http://www.yimao.info/tags/#github" target="_blank" rel="noopener">Coding</a></li>
<li><a href="http://www.yimao.info/tags/#markdown" target="_blank" rel="noopener">markDown</a></li>
</ul>
</blockquote>
<p>不懂的可以在本博客查看相应的文档:)</p>
<h3 id="1-1-Git安装"><a href="#1-1-Git安装" class="headerlink" title="1.1.Git安装"></a>1.1.Git安装</h3><p>去Git官网 <a href="https://git-scm.com/download" title="git官网" target="_blank" rel="noopener">https://git-scm.com/download</a> 安装相应的Git版本</p>
<p><img src="https://wx4.sinaimg.cn/large/006e1QBjly1folevzdp97j30w40e9tdu.jpg" alt="git下载" title="git下载"></p>
<p><em>提示:安装步骤省略</em></p>
<ul>
<li>完成安装之后，就可以使用命令行的 <code>git</code> 工具（已经自带了 ssh 客户端）了，另外还有一个图形界面的 Git 项目管理工具。</li>
</ul>
<h3 id="1-2-安装Node-js"><a href="#1-2-安装Node-js" class="headerlink" title="1.2. 安装Node.js"></a>1.2. 安装Node.js</h3><blockquote>
<ul>
<li><p>简单的说 Node.js 就是运行在服务端的 JavaScript。Node.js 是一个基于 <a href="https://developers.google.com/v8/" target="_blank" rel="noopener">Chrome V8</a> 引擎的 JavaScript 运行环境。Node.js 使用了一个事件驱动、非阻塞式 I/O 的模型，使其轻量又高效。Node.js 的包管理器 <a href="https://www.npmjs.com/" target="_blank" rel="noopener">npm</a>，是全球最大的开源库生态系统。</p>
</li>
<li><p>打开官网下载链接:<a href="https://nodejs.org/en/download/" target="_blank" rel="noopener">https://nodejs.org/en/download/</a> 我这里下载的是对应版本</p>
</li>
<li>至于什么是LTS?<blockquote>
<p>Node维护了着两条发布流程线：奇数版本每年的发布以后，偶数版本第二年的4月份发布。<br>当一个奇数版本发布后，最近的一个偶数版本会立即进入LTS维护计划<br>LTS期间支持的变更：bug fix，安全问题 fix, 文档更新和与未来新特性兼容问题的更新。<br>期间支持的变更： <strong>严重的</strong>bug fix，<strong>严重的</strong>安全问题 fix 或者文档更新</p>
</blockquote>
</li>
</ul>
</blockquote>
<p><img src="https://wx1.sinaimg.cn/large/006e1QBjly1folga6pgr0j30xz0kz75q.jpg" alt="Node.js下载" title="Node.js下载"></p>
<p>总之LTS意味着更加稳定，因此此处选择安装该版本。</p>
<h2 id="2-Hexo-同步Github-和coding"><a href="#2-Hexo-同步Github-和coding" class="headerlink" title="2.Hexo 同步Github 和coding"></a>2.Hexo 同步Github 和coding</h2><p>Hexo部署到GitHub上的文件，是.md（你的博文）转化之后的.html（静态网页）。因此为了方便当你重装电脑或者在不同电脑上修改博客时，思路是大概是这样</p>
<p>Hexo生成的网站文件中有.gitignore文件，因此它的本意也是想我们将Hexo生成的网站文件存放到GitHub上进行管理的,利用了建立GitHub Pages的仓库分支个用来存放Hexo网站的文件，一个用来发布网站html</p>
<blockquote>
<ol>
<li>创建仓库，yimaoinfo.github.io；</li>
<li>创建两个分支：master 与 hexo；</li>
<li>设置hexo为默认分支（因为我们只需要手动管理这个分支上的Hexo网站文件）；</li>
<li>使用git clone <a href="mailto:git@github.com" target="_blank" rel="noopener">git@github.com</a>:yimaoinfo/yimaoinfo.github.io.git拷贝仓库；</li>
<li>在本地yimaoinfo.github.io文件夹下通过Git bash依次执行博客搭建与更新</li>
</ol>
</blockquote>
<h3 id="2-1-GitHub"><a href="#2-1-GitHub" class="headerlink" title="2.1.GitHub"></a>2.1.GitHub</h3><h4 id="2-1-1-注册Github帐号"><a href="#2-1-1-注册Github帐号" class="headerlink" title="2.1.1.注册Github帐号"></a>2.1.1.注册Github帐号</h4><p>进入<em>Github</em> 首页进行注册，用户名、邮箱和密码之后都需要用到，自己记好，不知道怎么注册的童鞋去问问度娘</p>
<h4 id="2-1-2-创建Repository-Github-Pages"><a href="#2-1-2-创建Repository-Github-Pages" class="headerlink" title="2.1.2.创建Repository(Github Pages)"></a>2.1.2.创建Repository(Github Pages)</h4><p>Repository相当于一个仓库，用来放置你的代码文件。首先，登陆进入<em>Github</em>，选择首页中的 <code>New repository</code> 按钮</p>
<p><img src="https://wx2.sinaimg.cn/large/006e1QBjly1folgn0lguuj30y20biq43.jpg" alt="img" title="New repository"></p>
<p>创建时，只需要填写Repository name即可，可以顺便创建README文件，就是红色那个钩，当然这个名字的格式必须为<strong>{user_name}.github.io</strong>，其中<strong>{user_name}</strong>必须与你的用户名一样，这是github pages的<strong>特殊命名规范</strong>。</p>
<p><img src="https://wx1.sinaimg.cn/large/006e1QBjly1folgxyd03ej30rb0ksq46.jpg" alt="img"></p>
<h4 id="2-1-3-创建hexo分支"><a href="#2-1-3-创建hexo分支" class="headerlink" title="2.1.3.创建hexo分支"></a>2.1.3.创建hexo分支</h4><p><img src="https://wx1.sinaimg.cn/large/006e1QBjly1foli9t79o3j30yg0fht9p.jpg" alt="创建hexo分支" title="创建hexo分支"></p>
<h4 id="2-1-4-设置hexo为默认分支"><a href="#2-1-4-设置hexo为默认分支" class="headerlink" title="2.1.4.设置hexo为默认分支"></a>2.1.4.设置hexo为默认分支</h4><p>步骤为:点击 <code>Settings</code> —&gt; <code>Branches</code>  —&gt;选择<code>hexo</code> 分支后 ,点击<strong>Update</strong></p>
<p><img src="https://wx1.sinaimg.cn/large/006e1QBjly1folicfapwgj30zb0i5wfw.jpg" alt="设置hexo为默认分支"></p>
<h4 id="2-1-5-得到github仓库地址"><a href="#2-1-5-得到github仓库地址" class="headerlink" title="2.1.5.得到github仓库地址"></a>2.1.5.得到github仓库地址</h4><p>打开yimaoinfo.github.io仓库 复制 ssh 地址 </p>
<p><img src="https://wx1.sinaimg.cn/large/006e1QBjly1folhyrdyk8j30z20ebdh7.jpg" alt="得到仓库地址" title="得到仓库地址"></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git@github.com:yimaoinfo/yimaoinfo.github.io.git</span><br></pre></td></tr></table></figure>
<h3 id="2-2-Coding"><a href="#2-2-Coding" class="headerlink" title="2.2.Coding"></a>2.2.Coding</h3><h3 id="2-2-1-注册Coding帐号"><a href="#2-2-1-注册Coding帐号" class="headerlink" title="2.2.1.注册Coding帐号"></a>2.2.1.注册Coding帐号</h3><p>国内的网站，绝大部分都是中文的，注册什么的就不说了,进入<em>Coding</em> 滚键盘就是了= =</p>
<h4 id="2-2-2-创建项目-Coding-Pages"><a href="#2-2-2-创建项目-Coding-Pages" class="headerlink" title="2.2.2.创建项目(Coding Pages)"></a>2.2.2.创建项目(Coding Pages)</h4><p>Coding Pages请看 <em>Coding Pages</em><br>注册之后进入主页，点击项目，点击<strong>+</strong>，项目名为你的用户名, 创建时，只需要填写Repository name即可，可以顺便创建README文件，就是红色那个钩，当然这个名字的格式建议为<strong>{user_name}.coding.me</strong>，其中<strong>{user_name}</strong>与你的用户名一样，这是github pages的<strong>特殊命名规范</strong>。</p>
<p><img src="https://wx1.sinaimg.cn/large/006e1QBjly1folityz3u7j30rs0o6q4j.jpg" alt="创建coding仓库" title="创建coding仓库"></p>
<h4 id="2-2-3创建hexo分支-并设置hexo为默认分支"><a href="#2-2-3创建hexo分支-并设置hexo为默认分支" class="headerlink" title="2.2.3创建hexo分支,并设置hexo为默认分支"></a>2.2.3创建hexo分支,并设置hexo为默认分支</h4><p>点击  <code>分支</code> —&gt; <code>新建分支</code> —&gt;创建名为 <code>hexo</code> 分支 —&gt;点击 master后面的 <code>...</code> 设置 hexo 为默认分支 </p>
<p><img src="https://wx1.sinaimg.cn/large/006e1QBjly1foljbgzsjhj312o0dlwf9.jpg" alt="创建hexo分支,并设置hexo为默认分支" title="创建hexo分支,并设置hexo为默认分支"> </p>
<h4 id="2-2-4开启Pages-服务-绑定域名"><a href="#2-2-4开启Pages-服务-绑定域名" class="headerlink" title="2.2.4开启Pages 服务,绑定域名"></a>2.2.4开启Pages 服务,绑定域名</h4><p><img src="https://wx1.sinaimg.cn/large/006e1QBjly1folj4v4p00j311a0nd75o.jpg" alt="coding静态页面" title="coding静态页面"></p>
<h4 id="2-2-5复制coding-SSH-地址"><a href="#2-2-5复制coding-SSH-地址" class="headerlink" title="2.2.5复制coding SSH 地址"></a>2.2.5复制coding SSH 地址</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git@git.coding.net:yimaoinfo/yimaoinfo.coding.me.git</span><br></pre></td></tr></table></figure>
<h2 id="3-配置SSH与Git"><a href="#3-配置SSH与Git" class="headerlink" title="3.配置SSH与Git"></a>3.配置SSH与Git</h2><p>那么我们有了两个免费的服务器之后，就要绑定个人电脑与它们联系，那就是<strong>SSH</strong>与<strong>Git</strong><br>绑定之后我们每次部署项目就不用输入帐号和密码</p>
<h3 id="3-1-检查电脑是否已经有SSH-KEYS。"><a href="#3-1-检查电脑是否已经有SSH-KEYS。" class="headerlink" title="3.1. 检查电脑是否已经有SSH KEYS。"></a>3.1. 检查电脑是否已经有SSH KEYS。</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">$ ls -al ~/.ssh</span><br><span class="line"># Lists the files in your .ssh directory, if they exist</span><br></pre></td></tr></table></figure>
<p>默认情况下，public keys的文件名是以下的格式之一：id_dsa.pub、id_ecdsa.pub、id_ed25519.pub、id_rsa.pub。因此，如果列出的文件有public和private钥匙对（例如id_ras.pub和id_rsa），证明已存在SSH keys。</p>
<h3 id="3-2-如果没有SSH-KEY，则生成新的SSH-KEY。"><a href="#3-2-如果没有SSH-KEY，则生成新的SSH-KEY。" class="headerlink" title="3.2.如果没有SSH KEY，则生成新的SSH KEY。"></a>3.2.如果没有SSH KEY，则生成新的SSH KEY。</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ssh-keygen -t rsa -C your_email@youremail.com</span><br></pre></td></tr></table></figure>
<p>后面的 <a href="mailto:*your_email@youremail.com" target="_blank" rel="noopener">*your_email@youremail.com</a>*<br>改为你的邮箱，之后会要求确认路径和输入密码，我们这使用默认的一路回车就行。成功的话会在~/下生成 <code>.ssh</code> 文件夹，进去，打开 <code>id_rsa.pub</code>，复制里面的key，粗暴点就是 Ctrl+a 然后 Ctrl+c</p>
<h3 id="3-3-在GitHub和Coding添加SSH-KEY。"><a href="#3-3-在GitHub和Coding添加SSH-KEY。" class="headerlink" title="3.3.在GitHub和Coding添加SSH KEY。"></a>3.3.在GitHub和Coding添加SSH KEY。</h3><h4 id="3-3-1-GIthub-添加SSH-Key"><a href="#3-3-1-GIthub-添加SSH-Key" class="headerlink" title="3.3.1 GIthub 添加SSH Key"></a>3.3.1 GIthub 添加SSH Key</h4><p>首先是Github，登录Github，右上角 头像 -&gt; <code>Settings</code> —&gt; <code>SSH and GPG keys</code> —&gt; <code>New SSH key</code> 。把公钥粘贴到key中，填好title并点击 <code>Add SSH key</code> </p>
<p><img src="https://wx1.sinaimg.cn/large/006e1QBjly1foljvjtxinj30yx0f4my6.jpg" alt="SSH key" title="添加SSH key"></p>
<h4 id="3-3-2-Coding添加SSH-Key"><a href="#3-3-2-Coding添加SSH-Key" class="headerlink" title="3.3.2.Coding添加SSH Key"></a>3.3.2.Coding添加SSH Key</h4><p>至于Coding，登录进入主页，点击 <code>账户</code> —&gt; <code>SSH公钥</code> —&gt; 输入key再点击 <code>添加</code></p>
<p><img src="https://wx1.sinaimg.cn/large/006e1QBjly1folk0lttpcj30zb0i5wfw.jpg" alt="Coding SSH key" title="Coding SSH key"></p>
<h4 id="3-3-3-验证成功与否"><a href="#3-3-3-验证成功与否" class="headerlink" title="3.3.3.验证成功与否"></a>3.3.3.验证成功与否</h4><ul>
<li>验证github</li>
</ul>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ssh -T git@github.com</span><br></pre></td></tr></table></figure>
<p>如果是第一次的会提示是否continue，输入<strong>yes</strong>就会看到：You’ve successfully authenticated, but GitHub does not provide shell access 。这就表示已成功连上github!</p>
<ul>
<li>验证coding</li>
</ul>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ssh -T git@git.coding.net</span><br></pre></td></tr></table></figure>
<p>同上，按<strong>yes</strong><br>接下来我们要做的就是把本地仓库传到github上去，在此之前还需要设置username和email，因为github每次commit都会记录他们</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">git config --global user.name your name</span><br><span class="line">git config --global user.email your_email@youremail.com</span><br></pre></td></tr></table></figure>
<h2 id="4-博客安装"><a href="#4-博客安装" class="headerlink" title="4.博客安装"></a>4.博客安装</h2><p>找到一个盘符下 进行操作, 我选的是D:\ , 在该盘符下需要在Git终端中执行(右键单击 -&gt; <code>Git bash</code>)。</p>
<p>使用<code>git clone git@github.com:yimaoinfo/yimaoinfo.github.io.git</code>拷贝仓库,会得到一个<strong>D:\yimaoinfo.github.io</strong>文件夹,先把这个文件夹下的内容备份,因为接下来的hexo init 会清空文件夹内容 ( <strong>.git</strong> 与<strong>README.md</strong> 文件,如果不显示.git , 去文件夹选项 显示隐藏内容)</p>
<ul>
<li><p>在 <strong>D:\yimaoinfo.github.io</strong> 文件夹下右键单击 -&gt; <code>Git bash</code></p>
</li>
<li><p>安装淘宝nmp源: <code>npm install -g cnpm --registry=https://registry.npm.taobao.org</code></p>
</li>
<li><p>安装hexo：<code>cnpm install -g hexo</code></p>
</li>
<li><p>创建hexo文件夹：新建放置博客的文件夹，进入并执行命令<code>hexo init</code>。hexo 会在目标文件夹建立网站所需要的所有文件。</p>
</li>
<li><p>安装依赖包：<code>cnpm install</code>  到此，Hexo的安装已基本完成，可以先试一下<strong>Hello World</strong>。</p>
</li>
<li><p>预览博客:  <code>hexo s</code> 开启博客本地访问 <a href="http://localhost:4000" target="_blank" rel="noopener">http://localhost:4000</a>   <code>Ctrl + C</code> 结束本地访问</p>
</li>
</ul>
<p><img src="https://wx1.sinaimg.cn/large/006e1QBjly1folm3vebdfj31fq0qgqjg.jpg" alt="Hexo" title="hexo"></p>
<p>注意: 在 hexo init 以后随时都可以把文件夹D:\yimaoinfo.github.io之前的备份内容考入进去</p>
<h2 id="5-部署到Github与Coding"><a href="#5-部署到Github与Coding" class="headerlink" title="5.部署到Github与Coding"></a>5.部署到Github与Coding</h2><h3 id="5-1-在此之前，先安装Git部署插件"><a href="#5-1-在此之前，先安装Git部署插件" class="headerlink" title="5.1.在此之前，先安装Git部署插件"></a>5.1.在此之前，先安装Git部署插件</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">cnpm install hexo-deployer-git --save</span><br></pre></td></tr></table></figure>
<h3 id="5-2-打开站点配置文件，拉到底部，修改部署配置："><a href="#5-2-打开站点配置文件，拉到底部，修改部署配置：" class="headerlink" title="5.2.打开站点配置文件，拉到底部，修改部署配置："></a>5.2.打开站点配置文件，拉到底部，修改部署配置：</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"># Deployment</span><br><span class="line">## Docs: https://hexo.io/docs/deployment.html</span><br><span class="line">deploy:</span><br><span class="line">  type: git</span><br><span class="line">  repo:</span><br><span class="line">    github: git@github.com:yimaoinfo/yimaoinfo.github.io.git</span><br><span class="line">    coding: git@git.coding.net:yimaoinfo/yimaoinfo.coding.me.git</span><br><span class="line">  branch: master</span><br></pre></td></tr></table></figure>
<h3 id="5-3-注意冒号后面是网站对应的用户名，接着就是仓库地址然后上分支后-保存后终端执行"><a href="#5-3-注意冒号后面是网站对应的用户名，接着就是仓库地址然后上分支后-保存后终端执行" class="headerlink" title="5.3.注意冒号后面是网站对应的用户名，接着就是仓库地址然后上分支后, 保存后终端执行"></a>5.3.注意冒号后面是网站对应的用户名，接着就是仓库地址然后上分支后, 保存后终端执行</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">hexo clean        #清除缓存</span><br><span class="line">hexo g					# 等同于hexo generate，生成静态文件</span><br><span class="line">hexo d					# 等同于hexo server，在本地服务器运行</span><br></pre></td></tr></table></figure>
<h3 id="5-4-访问博客"><a href="#5-4-访问博客" class="headerlink" title="5.4.访问博客"></a>5.4.访问博客</h3><p>稍等片刻，可能会由于环境、网络等原因，部署的时间会有偏差，有的人快有的慢,部署完成后可在浏览器输入 <code>yourName.github.io</code> 或者 <code>yourName.coding.me</code> 或者绑定的域名 都可以浏览自己的博客了 ～</p>
<h2 id="6-日常修改"><a href="#6-日常修改" class="headerlink" title="6.日常修改"></a>6.日常修改</h2><p>在本地对博客进行修改（添加新博文、修改样式等等）后，通过下面的流程进行管理：</p>
<ol>
<li>依次执行<code>git add .</code>、<code>git commit -m “…”</code>、<code>git push origin hexo</code>指令将改动推送到GitHub（此时当前分支应为<strong>hexo</strong>）；</li>
<li>然后才执行<code>hexo g -d</code>发布网站到master分支上。</li>
</ol>
<p>虽然两个过程顺序调转一般不会有问题，不过逻辑上这样的顺序是绝对没问题的。</p>
<h2 id="7-本地资料丢失"><a href="#7-本地资料丢失" class="headerlink" title="7.本地资料丢失"></a>7.本地资料丢失</h2><p>当重装电脑之后，或者想在其他电脑上修改博客，可以使用下列步骤：</p>
<ol>
<li>使用<code>git clone git@github.com:yimaoinfo/yimaoinfo.github.io.git</code>拷贝仓库（默认分支为hexo）；</li>
<li>在本地新拷贝的yimaoinfo.github.io文件夹下通过Git bash依次执行下列指令：<code>cnpm install hexo</code>、<code>cnpm install</code>、<code>cnpm install hexo-deployer-git --save</code>（注意，不需要hexo init这条指令）。</li>
</ol>
<h2 id="8-总结"><a href="#8-总结" class="headerlink" title="8.总结"></a>8.总结</h2><p>不积跬步无以至千里,  Hexo博客的使用体会，四个字总结：多、快、好、省。 </p>

      
    </div>

    

<div>
  
    <div>
    
        <div style="text-align:center;color: #A52A2A; font-size:18px;"> &lt; - 完 - &gt; </div>
    
</div>
  
</div>
    
    
    

    
      <div>
        <div id="wechat_subscriber" style="display: block; padding: 10px 0; margin: 20px auto; width: 100%; text-align: center">
    <img id="wechat_subscriber_qcode" src="/img/hongbao-qcode.jpg" alt="一毛 wechat" style="width: 260px; max-width: 100%;"/>
    <div>每天用 支付宝 扫一扫免费抢最高99现金 ☺</div>
</div>

      </div>
    

    
      <div>
        <div style="padding: 10px 0; margin: 20px auto; width: 90%; text-align: center;">
  <div>帮我早餐加鸡腿  :)</div>
  <button id="rewardButton" disable="enable" onclick="var qr = document.getElementById('QR'); if (qr.style.display === 'none') {qr.style.display='block';} else {qr.style.display='none'}">
    <span>打赏</span>
  </button>
  <div id="QR" style="display: none;">

    
      <div id="wechat" style="display: inline-block">
        <img id="wechat_qr" src="/img/wechatpay.jpg" alt="一毛 微信支付"/>
        <p>微信支付</p>
      </div>
    

    

    

  </div>
</div>

      </div>
    

    
      <div>
        <ul class="post-copyright">
  <li class="post-copyright-author">
    <strong>本文作者： </strong>一毛</li>
  <li class="post-copyright-link">
    <strong>本文链接：</strong>
    <a href="http://yimao.info/2018/02/19/hexo-to-github-and-coding/" title="Hexo搭建Github+Coding双线博客">http://yimao.info/2018/02/19/hexo-to-github-and-coding/</a>
  </li>
  <li class="post-copyright-license">
    <strong>版权声明： </strong>本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" rel="external nofollow" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明出处！</li>
</ul>

      </div>
    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/Hexo/" rel="tag"><i class="fa fa-tag"></i> Hexo</a>
          
            <a href="/tags/Hexo博客搭建/" rel="tag"><i class="fa fa-tag"></i> Hexo博客搭建</a>
          
            <a href="/tags/Hexo-Github-Coding/" rel="tag"><i class="fa fa-tag"></i> Hexo Github Coding</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2018/02/17/Markdown-study/" rel="next" title="Markdown中文语法教程文档">
                <i class="fa fa-chevron-left"></i> Markdown中文语法教程文档
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image"
                src="/img/avatar.jpg"
                alt="一毛" />
            
              <p class="site-author-name" itemprop="name">一毛</p>
              <p class="site-description motion-element" itemprop="description">想活成别人幻想中的样子</p>
          </div>

          
            <nav class="site-state motion-element">
              
                <div class="site-state-item site-state-posts">
                
                  <a href="/archives/">
                
                    <span class="site-state-item-count">8</span>
                    <span class="site-state-item-name">日志</span>
                  </a>
                </div>
              

              
                
                
                <div class="site-state-item site-state-categories">
                  <a href="/categories/index.html">
                    
                    
                      
                    
                      
                    
                      
                    
                    <span class="site-state-item-count">3</span>
                    <span class="site-state-item-name">分类</span>
                  </a>
                </div>
              

              
                
                
                <div class="site-state-item site-state-tags">
                  <a href="/tags/index.html">
                    
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                    <span class="site-state-item-count">15</span>
                    <span class="site-state-item-name">标签</span>
                  </a>
                </div>
              
            </nav>
          

          

          

          
          

          
          
            <div class="links-of-blogroll motion-element links-of-blogroll-block">
              <div class="links-of-blogroll-title">
                <i class="fa  fa-fw fa-link"></i>
                友情链接
              </div>
              <ul class="links-of-blogroll-list">
                
                  <li class="links-of-blogroll-item">
                    <a href="http://yimao.info" title="一毛" target="_blank" rel="external nofollow" >一毛</a>
                  </li>
                
              </ul>
            </div>
          

          
            
          
          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#1-环境"><span class="nav-text">1.环境</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#1-1-Git安装"><span class="nav-text">1.1.Git安装</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#1-2-安装Node-js"><span class="nav-text">1.2. 安装Node.js</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-Hexo-同步Github-和coding"><span class="nav-text">2.Hexo 同步Github 和coding</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#2-1-GitHub"><span class="nav-text">2.1.GitHub</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#2-1-1-注册Github帐号"><span class="nav-text">2.1.1.注册Github帐号</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#2-1-2-创建Repository-Github-Pages"><span class="nav-text">2.1.2.创建Repository(Github Pages)</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#2-1-3-创建hexo分支"><span class="nav-text">2.1.3.创建hexo分支</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#2-1-4-设置hexo为默认分支"><span class="nav-text">2.1.4.设置hexo为默认分支</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#2-1-5-得到github仓库地址"><span class="nav-text">2.1.5.得到github仓库地址</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-2-Coding"><span class="nav-text">2.2.Coding</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-2-1-注册Coding帐号"><span class="nav-text">2.2.1.注册Coding帐号</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#2-2-2-创建项目-Coding-Pages"><span class="nav-text">2.2.2.创建项目(Coding Pages)</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#2-2-3创建hexo分支-并设置hexo为默认分支"><span class="nav-text">2.2.3创建hexo分支,并设置hexo为默认分支</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#2-2-4开启Pages-服务-绑定域名"><span class="nav-text">2.2.4开启Pages 服务,绑定域名</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#2-2-5复制coding-SSH-地址"><span class="nav-text">2.2.5复制coding SSH 地址</span></a></li></ol></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3-配置SSH与Git"><span class="nav-text">3.配置SSH与Git</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#3-1-检查电脑是否已经有SSH-KEYS。"><span class="nav-text">3.1. 检查电脑是否已经有SSH KEYS。</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#3-2-如果没有SSH-KEY，则生成新的SSH-KEY。"><span class="nav-text">3.2.如果没有SSH KEY，则生成新的SSH KEY。</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#3-3-在GitHub和Coding添加SSH-KEY。"><span class="nav-text">3.3.在GitHub和Coding添加SSH KEY。</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#3-3-1-GIthub-添加SSH-Key"><span class="nav-text">3.3.1 GIthub 添加SSH Key</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#3-3-2-Coding添加SSH-Key"><span class="nav-text">3.3.2.Coding添加SSH Key</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#3-3-3-验证成功与否"><span class="nav-text">3.3.3.验证成功与否</span></a></li></ol></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#4-博客安装"><span class="nav-text">4.博客安装</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#5-部署到Github与Coding"><span class="nav-text">5.部署到Github与Coding</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#5-1-在此之前，先安装Git部署插件"><span class="nav-text">5.1.在此之前，先安装Git部署插件</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#5-2-打开站点配置文件，拉到底部，修改部署配置："><span class="nav-text">5.2.打开站点配置文件，拉到底部，修改部署配置：</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#5-3-注意冒号后面是网站对应的用户名，接着就是仓库地址然后上分支后-保存后终端执行"><span class="nav-text">5.3.注意冒号后面是网站对应的用户名，接着就是仓库地址然后上分支后, 保存后终端执行</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#5-4-访问博客"><span class="nav-text">5.4.访问博客</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#6-日常修改"><span class="nav-text">6.日常修改</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#7-本地资料丢失"><span class="nav-text">7.本地资料丢失</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#8-总结"><span class="nav-text">8.总结</span></a></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; 2015 &mdash; <span itemprop="copyrightYear">2018</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">一毛</span>

  

  
</div>




  <div class="powered-by"><a class="theme-link" target="_blank" href="../sitemap.xml">站点地图</a></div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">Hosted by <a class="theme-link" style="font-weight: bold" target="_blank" href="https://pages.coding.me">Coding Pages</a></div>




        








        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>












  



  













  
  
    <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  

  
  
    <script type="text/javascript" src="/lib/canvas-nest/canvas-nest.min.js"></script>
  


  


  <script type="text/javascript" src="/js/src/utils.js?v=6.0.4"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=6.0.4"></script>



  
  


  <script type="text/javascript" src="/js/src/affix.js?v=6.0.4"></script>

  <script type="text/javascript" src="/js/src/schemes/pisces.js?v=6.0.4"></script>



  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=6.0.4"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=6.0.4"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=6.0.4"></script>



  



	





  





  










  





  

  
  <script src="https://cdn1.lncld.net/static/js/av-core-mini-0.6.4.js"></script>
  <script>AV.initialize("cGN6UsMS1KSbRPC9aq6aOP7H-gzGzoHsz", "TPnd3Yzf5aKN3n8xTM2G9bk3");</script>
  <script>
    function showTime(Counter) {
      var query = new AV.Query(Counter);
      var entries = [];
      var $visitors = $(".leancloud_visitors");

      $visitors.each(function () {
        entries.push( $(this).attr("id").trim() );
      });

      query.containedIn('url', entries);
      query.find()
        .done(function (results) {
          var COUNT_CONTAINER_REF = '.leancloud-visitors-count';

          if (results.length === 0) {
            $visitors.find(COUNT_CONTAINER_REF).text(0);
            return;
          }

          for (var i = 0; i < results.length; i++) {
            var item = results[i];
            var url = item.get('url');
            var time = item.get('time');
            var element = document.getElementById(url);

            $(element).find(COUNT_CONTAINER_REF).text(time);
          }
          for(var i = 0; i < entries.length; i++) {
            var url = entries[i];
            var element = document.getElementById(url);
            var countSpan = $(element).find(COUNT_CONTAINER_REF);
            if( countSpan.text() == '') {
              countSpan.text(0);
            }
          }
        })
        .fail(function (object, error) {
          console.log("Error: " + error.code + " " + error.message);
        });
    }

    function addCount(Counter) {
      var $visitors = $(".leancloud_visitors");
      var url = $visitors.attr('id').trim();
      var title = $visitors.attr('data-flag-title').trim();
      var query = new AV.Query(Counter);

      query.equalTo("url", url);
      query.find({
        success: function(results) {
          if (results.length > 0) {
            var counter = results[0];
            counter.fetchWhenSave(true);
            counter.increment("time");
            counter.save(null, {
              success: function(counter) {
                var $element = $(document.getElementById(url));
                $element.find('.leancloud-visitors-count').text(counter.get('time'));
              },
              error: function(counter, error) {
                console.log('Failed to save Visitor num, with error message: ' + error.message);
              }
            });
          } else {
            var newcounter = new Counter();
            /* Set ACL */
            var acl = new AV.ACL();
            acl.setPublicReadAccess(true);
            acl.setPublicWriteAccess(true);
            newcounter.setACL(acl);
            /* End Set ACL */
            newcounter.set("title", title);
            newcounter.set("url", url);
            newcounter.set("time", 1);
            newcounter.save(null, {
              success: function(newcounter) {
                var $element = $(document.getElementById(url));
                $element.find('.leancloud-visitors-count').text(newcounter.get('time'));
              },
              error: function(newcounter, error) {
                console.log('Failed to create');
              }
            });
          }
        },
        error: function(error) {
          console.log('Error:' + error.code + " " + error.message);
        }
      });
    }

    $(function() {
      var Counter = AV.Object.extend("Counter");
      if ($('.leancloud_visitors').length == 1) {
        addCount(Counter);
      } else if ($('.post-title-link').length > 1) {
        showTime(Counter);
      }
    });
  </script>



  

  

  

  
  

  

  

  

  

</body>
</html>
